﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Unleashed.AutoUpdate.IO.Configuration;
using System.Diagnostics;
using System.IO;
using System.Runtime.Remoting;

namespace Unleashed.AutoUpdate.CustomActions
{
    public static class ReflectionLoader
    {
        public static CustomAction LoadInstance(string assemblyPath, string className)
        {
            if (String.IsNullOrEmpty(assemblyPath) || String.IsNullOrEmpty(className))
            {
                throw new Exception("null path or name");
                // return null;
            }

            CustomAction res;
            try
            {
                Debug.WriteLine("AssemblyPath" + assemblyPath);
                Debug.WriteLine("ClassName" + className);
                Debug.WriteLine(assemblyPath);
                ObjectHandle handle = Activator.CreateInstanceFrom(assemblyPath, className);
                res = (CustomAction)handle.Unwrap();

                Debug.WriteLine("res is null" + (res == null));   
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                res = null;
            }

            return res;
        }
    }
}